package com.chuangke.common.express.function.date;

import java.util.Date;
import java.util.Map;

import com.chuangke.common.utils.DateUtils;
import com.googlecode.aviator.runtime.function.AbstractFunction;
import com.googlecode.aviator.runtime.type.AviatorObject;
import com.googlecode.aviator.runtime.type.AviatorString;

public class DateFunction extends AbstractFunction {
	
	
    private static final long serialVersionUID = -5914355570663053279L;

	@Override
	public AviatorObject call(Map<String, Object> env, AviatorObject arg1) {
		Date date = new Date();
		String pattern = (String) arg1.getValue(env);
		return new AviatorString(DateUtils.getDate(date, pattern));
	}
	
	@Override
	public AviatorObject call(Map<String, Object> env, AviatorObject arg1,AviatorObject arg2) {
		String pattern = (String) arg1.getValue(env);
		Date date = (Date) arg2.getValue(env);
		return new AviatorString(DateUtils.getDate(date, pattern));
	}

	@Override
	public String getName() {
		return "date";
	}

}
